#include<bits/stdc++.h>
using namespace std;
const int N = 310;
struct tlb{
	int c , m , e;
	int s;
	int x;
}a[N];
bool cmp(tlb a , tlb b){
	if(a.s != b.s){
		return a.s > b.s;
	}
	if(a.c != b.c){
		return a.c > b.c;
	}
	return a.x < b.x;
}
int main(){
	freopen("scholar.in", "r", stdin);
	freopen("scholar.out", "w", stdout);
	int n;
	cin >> n;
	for(int i = 1 ; i <= n ; i++){
		cin >> a[i].c >> a[i].e >> a[i].m;
		a[i].s = a[i].c + a[i].e + a[i].m;
		a[i].x = i;
	}
	sort(a + 1 , a + n + 1 , cmp);
	for(int i = 1 ; i <= 5 ; i++){
		cout << a[i].x << " " << a[i].s << endl;
	}
	return 0;
}